<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :inline="true" :model="queryParams" label-width="98px" ref="queryForm" size="small" v-show="showSearch">
      <el-form-item label="订单编号" prop="projectNo">
        <el-input v-model="queryParams.projectNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input @keyup.enter.native="handleQuery" clearable placeholder="请输入客户名称"
          v-model="queryParams.customerName" />
      </el-form-item>
      <!-- <el-form-item label="供应商名称" prop="supplierName">-->
      <!--      <el-form-item label="销售日期" prop="type">
        <el-date-picker
          :picker-options="pickerOptions"
          @change="selectDateRange"
          align="right"
          end-placeholder="结束日期"
          range-separator="至"
          start-placeholder="开始日期"
          type="daterange"
          unlink-panels
          v-model="queryParams.dateRange"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>-->
      <!--<el-form-item label="是否开票" prop="invoice">
        <el-select clearable placeholder="是否开票" style="width: 130px" v-model="queryParams.invoice">
          <el-option :key="dict.value"
                     :label="dict.label" :value="dict.value" v-for="dict in dict.type.yes_no"/>
        </el-select>
        &lt;!&ndash;        <el-input v-model="queryParams.invoice" placeholder="请输入是否开票" clearable @keyup.enter.native="handleQuery"/>&ndash;&gt;
      </el-form-item>-->
      <el-form-item label="工程名称" prop="gongchengName">
        <el-input @keyup.enter.native="handleQuery" clearable placeholder="请输入工程名称"
          v-model="queryParams.gongchengName" />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
        <!--  <el-button @click="handleExport" icon="el-icon-download" plain size="mini"
                   type="warning">导出
        </el-button>-->
      </el-form-item>
    </el-form>

    <div class="app-container">
      <!--<el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                     v-hasPermi="['develop:GoodsOrderIn:add']">新增
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>-->
      <el-table border v-loading="loading"  :data="dataList" ref="table" :max-height="tableMaxHeight">
        <!--<el-table-column label="客户名称" align="center" prop="customerName" width="160">
          <template slot-scope="scope">
            {{scope.row.customerName}}
          </template>
        </el-table-column>-->
        <!-- <el-table-column label="招标人" align="center" prop="companyName"  show-overflow-tooltip />-->
        <el-table-column label="客户名称/买方" align="center" prop="order.customName" show-overflow-tooltip  />
        <!--<template slot-scope="scope">
            {{scope.row.companyName}}
          </template>
        </el-table-column>-->
        <el-table-column label="工程名称" align="center" prop="gongchengName" show-overflow-tooltip  />
        <el-table-column label="订单编号" align="center" prop="projectId" >
          <template slot-scope="scope">
            <dict-tag :options="PrjNameOptions" :value="scope.row.projectId" />
          </template>
        </el-table-column>
        <!--<el-table-column label="供应商名称" align="center" prop="supplierName"/>-->
        <el-table-column label="产品名称" align="center" prop="goodsName" show-overflow-tooltip  />
        <el-table-column label="产品型号" align="center" prop="goodModel" show-overflow-tooltip  />
        <!-- <el-table-column label="产品型号明细" align="center" prop="goodsBrand"/>-->
        <el-table-column label="计量单位" align="center" prop="unit"  />
        <el-table-column label="单价" align="center" prop="goodsUnitPrice"  />
        <el-table-column label="销售数量" align="center" prop="orderCount"  />
        <el-table-column label="总价" align="center" prop="goodsTotalPrice"  />
        <!--<el-table-column label="销售人姓名" align="center" prop="saleName"/>-->
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-info" @click="choseyongliaoMingxi(scope.row)">选用记录</el-button>
            <!--<el-button size="mini" type="text" icon="el-icon-info"
                       @click="zizhiView(scope.row)">自制记录明细
            </el-button>-->
            <!--<el-button size="mini" type="text" icon="el-icon-info"
                       @click="handleView(scope.row)">锁定记录
            </el-button>-->
          </template>
        </el-table-column>
        <!--<el-table-column label="操作"  fixed="right"  align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-info"
                       @click="handleView(scope.row)">详情
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-edit"
                       @click="handleUpdate(scope.row)">修改
            </el-button>
            <el-popconfirm :title="`确认删除 `+scope.row.id+` 数据项？`"
                           @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete">删除
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>-->

      </el-table>

      <goodsSale-form @ok="getList" ref="goodsSaleForm"></goodsSale-form>
      <YongliaoMingxi-form-list ref="yongliaoMingxiForm" @ok="getList"></YongliaoMingxi-form-list>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </el-dialog>
</template>

<script>
  import {
    deleteAction,
    downloadFile,
    getAction,
    getById
  } from '@/api/manage'
  import GoodsSaleForm from "./GoodsSaleForm";
  import YongliaoMingxiFormList from '@/views/develop/goodsSaleMaterial/module/YongliaoMingxiFormList'

  export default {
    name: "GoodsSaleListFormInfo",
    dicts: ['fund_callback', 'sale_type', 'yes_no'],
    components: {
      GoodsSaleForm,
      YongliaoMingxiFormList,
    },
    data() {
      return {
        title: "记录",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          projectNo: null,
          goodsId: null,
          goodsName: null,
          goodsBrand: null,
          goodsUnitPrice: null,
          goodsCount: null,
          goodsTotalPrice: null,
          saleDate: null,
          supplierId: null,
          supplierName: null,
          customerId: null,
          customerName: null,
          gongchengName: null,
          invoice: null,
          invoiceId: null,
          invoiceNo: null,
          fundCallback: null,
          receipt: null,
          saleId: null,
          saleName: null,
          dateRange: "",
          params: {},
        },
        url: {
          listIds: '/goodsSale/goodsSale/listIds/',
          list: '/goodsSale/goodsSale/list',
          remove: '/goodsSale/goodsSale/',
          export: '/goodsSale/goodsSale/export',
          delete: '/goodsSale/goodsSale/deleteOrderin/',
          prjNames: '/projectBaseInfo/projectBaseInfo/prjNames',
        },
        PrjNameOptions: [],
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      zizhiView(row) {
        this.$refs.zizhiViewForm.show(row);
      },
      choseyongliaoMingxi(row) {
        this.$refs.yongliaoMingxiForm.show(row);
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      handleAdd() {
        this.$refs.goodsSaleForm.addGoodsSale(this.rows);
      },
      handleUpdate(row) {
        this.$refs.goodsSaleForm.handleUpdate(row);
      },
      handleView(row) {
        this.$refs.goodsSaleForm.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.delete, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      showSaleRecordForOrder(order) {
        this.rows = order;
        let that = this;
        let orderId = order.id;
        that.queryParams.goodsId = orderId;
        that.getList();
        that.open = true;
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      intDictsForPrj() {
        let that = this;
        getAction(that.url.prjNames, {}).then(res => {
          that.PrjNameOptions = res.data.nameList;
        })
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
    }
  };
</script>
